package com.eric.text;

import java.util.List;

import org.fnlp.nlp.cn.CNFactory;
import org.fnlp.util.exception.LoadModelException;
import org.jsoup.nodes.Document;

import com.eric.utils.ListUtils;

public class FNLPSegWorker extends AbstractTextWorker {

	private String modelPath = "models";// Default

	CNFactory f;

	public FNLPSegWorker(Object input) {
		super(input);
	}

	public void initThis() {
		try {
			f = CNFactory.getInstance(modelPath);

			if (customWords.size() > 0)
				CNFactory.addDict(customWords);

		} catch (LoadModelException e) {
			e.printStackTrace();
		}
	}

	@Override
	public void produce() {
		init();
		initThis();
		seg();
		System.out.println(">>>>>>Segment Results : <<<<<<");
		ListUtils.printList(result());
	}

	public void modelPath(String modelPath) {
		this.modelPath = modelPath;
	}

	/**
	 * 直接对已经下载好的Document分词
	 * 
	 * @param doc
	 *            Jsoup document
	 * @return
	 */
	private FNLPSegWorker seg() {
		String[] seg = f.seg(text);

		for (String s : seg) {
			if (acceptedText(s))
				result.add(s.trim());
		}

		if (removeStopWords)
			removeStopWords(result, stopWords);

		return this;
	}

	@Override
	public List<String> getContext() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<String> produce(String text, Document doc) {
		// TODO Auto-generated method stub
		return null;
	}

}
